/*
* TCSS 422, Project 2 (Scheduler Simulation)
* Team 9 Name: blueraccoon422
* Team 9 Group Members: Jacob Hall, Jacob Mertens, Diana Gorun, Alex Stringham
* File Name: Process.h
* Date: May 22, 2013
*/

#ifndef PROCESS_H_
#define PROCESS_H_
#include "Queue.h"
#define TRUE 1
#define FALSE 0
#define STOP FALSE

//what type of scheduling;
int scheduling;
/*
 * Process's state.
 */
typedef enum process_state {
        RUNNABLE,
        RUNNING,
        BLOCKED,
        INTERRUPTED
}PROCESS_STATE;
//count the number of process that will be created.
int counter;
/*
 * Process's type.
 */
typedef enum process_type {
		IDLE_PROCESS,
		IO_PROCESS,
        KEYBOARD_PROCESS,
        AUXILIARY_PROCESS,
        CALCULATOR_PROCESS,
        PRODUCER_PROCESS,
        CONSUMER_PROCESS
}PROCESS_TYPE;

/*
 * priority type.
 */
typedef enum priority_type {
        NOT_USE,        // we want the priority to start from 1.
        CALCULATOR,
        CONSUMER,
        PRODUCER,
        AUXILIARY,
        KEYBOARD,
}PRIORITY;
/*
 * request's type.
 */
typedef enum request_type {
        NO_REQUEST, // for calculator.
        KEYBOARD_IO_REQUEST,
        AUXILIARY_IO_REQUEST,
        PRODUCER_REQUEST,
        CONSUMER_REQUEST,
}REQUEST_TYPE;
/*
 * a request struct.
 */
typedef struct request_str {
        int step;
        REQUEST_TYPE request_type;
}RequestStr;
typedef RequestStr* RequestPtr;
/*
 * a process struct.
 */
typedef struct process_str {
        char * name;            // process's name.
        int id;                 // process's id.
        int no_steps;           // number of instructions.
        int no_requests;        // number of requests that will be generated during the process run.
        PRIORITY priority;      // process's priority, use for priority scheduling.
        int memory_location;    // semaphore count for consumer/producer.
        RequestStr * requests;  // an array of request, each request is issued at a specific time.
        PROCESS_TYPE pro_type;  //ex: calculator/keyboard.
        int ticketCount;
}ProcessStr;

typedef ProcessStr* ProcessPtr;
/*
 * a process control block.
 */
typedef struct process_control_block {
        int next_step;                  //step count that CPU had gotten to when this process was preempted.
        PROCESS_STATE state;    //the state of the process.
        Queue* queue;                   //the queue which the process is associated with.
        ProcessPtr process;    // point to the address of the process.
}PCBStr;
typedef PCBStr* PCBPtr;

//a global process control table, contain the processes different by id.
PCBPtr pcbTable;
// Function Prototype.
int num_request(PROCESS_TYPE, int);
RequestStr* request_array_init(PROCESS_TYPE, int, int);
ProcessStr* process_init(int, int, RequestStr*, PROCESS_TYPE, char*, int, int, int, int);
void PCB_init(ProcessStr*,int);
REQUEST_TYPE is_request(ProcessStr*, int);
int getch();
#endif /* PROCESS_H_ */
